//
//  KKView.m
//  GCDDemo
//
//  Created by 程强 on 16/7/5.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "KKView.h"

@implementation KKView
- (instancetype)initWithBlock:(void(^)(KKView *view))block
{
    if (self = [super init]) {
        if (block) {
            block(self);
        }
    }
    return self;
}
- (KKView *(^)(CGRect viewframe))viewFrame
{
    return ^KKView *(CGRect viewFrame){
        self.frame = viewFrame;
        return self;
    };
}
- (KKView *(^)(UIColor *color))viewBackgroundColor
{
    return ^KKView *(UIColor *color){
        [self setBackgroundColor:color];
        return self;
    };
}
@end

@implementation KKLabel
- (instancetype)init
{
    if (self = [super init]) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
- (instancetype)initWithBlock:(void (^)(KKLabel *lbl))block
{
    if (self = [super init]) {
        if (block) {
            block(self);
        }
    }
    return self;
}
- (KKLabel *(^)(CGRect laframe))laFrame
{
    return ^KKLabel *(CGRect frame){
        self.frame = frame;
        return self;
    };
}
- (KKLabel *(^)(NSString *text,UIColor *textColor,UIFont *font,NSTextAlignment alignment))laText
{
    return ^KKLabel *(NSString *text,UIColor *textColor,UIFont*font,NSTextAlignment alignment){
        self.text = text;
        self.textColor = textColor;
        self.font = font;
        self.textAlignment = alignment;
        return self;
    };
}
- (KKLabel *(^)(CGFloat radius))laRadius
{
    return ^KKLabel *(CGFloat radius){
        self.layer.cornerRadius = radius;
        return self;
    };
}

@end

@implementation KKButton
- (instancetype)initWithBackgroundImage:(NSString *)img selectImage:(NSString *)select_img title:(NSString *)title titleColor:(UIColor *)titleColor
{
    if (self = [super init]) {
        [self setBackgroundImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage imageNamed:select_img] forState:UIControlStateSelected];
        [self setTitle:title forState:UIControlStateNormal];
        [self setTitleColor:titleColor forState:UIControlStateNormal];
        [self addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}
- (void)btnClick:(UIButton *)sender
{
    if (self.block) {
        self.block(sender);
    }
}
- (void)clickEvent:(ClickBlock)click
{
    self.block = click;
}
- (instancetype)initWithBlock:(void(^)(KKButton *btn))bok
{
    if (self = [super init]) {
        [self addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        if (bok) {
            bok(self);
        }
    }
    return self;
}
- (KKButton *(^)(NSString *image))backgroundImage
{
    return ^KKButton *(NSString *image){
        [self setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
        return self;
    };
}
- (KKButton *(^)(NSString *image))selectedImage
{
    return ^KKButton *(NSString *image){
        [self setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateSelected];
        return self;
    };
}
- (KKButton *(^)(NSString *title))btnTitle
{
    return ^KKButton *(NSString *title){
        [self setTitle:title forState:UIControlStateNormal];
        return self;
    };
}
- (KKButton *(^)(UIColor *color))titleNormalColor
{
    return ^KKButton *(UIColor *color){
        [self setTitleColor:color forState:UIControlStateNormal];
        return self;
    };
}
- (KKButton *(^)(UIColor *color))titleSelectedlColor
{
    return ^KKButton *(UIColor *color){
        [self setTitleColor:color forState:UIControlStateSelected];
        return self;
    };
}
- (KKButton *(^)(CGRect frame))btnFrame
{
    return ^KKButton *(CGRect frame){
        self.frame = frame;
        return self;
    };
}
- (KKButton *(^)(UIFont *font))btnFont
{
    return ^KKButton *(UIFont *font){
        self.titleLabel.font = font;
        return self;
    };
}
@end